/*fq*/
angular.module('indexApp')
    .controller('activity_detailCtrl', function ($scope, $state, $rootScope, $http, $stateParams) {
        var vm = this;
        $scope.state = $state;
        vm.http = $rootScope.http;
        vm.alert=false;
        $http({
            method: 'post',
            url: $rootScope.http + 'activity_info',
            data: {
                activity_id: $stateParams.id
            }
        })
            .then(function successCallback(res) {
                console.log(res.data);
                if (res.data.code == 0) {
                    vm.data = res.data.data;
                    $('#content').html(vm.data.content.content)
                }
            }, function errorCallback(res) {// 请求失败执行代码
                $rootScope.alertError()
            });
        vm.choose = function () {
            bootbox.confirm({
                message: "报名之前需要先填写注册信息，是否确认注册？",
                buttons: {
                    confirm: {
                        label: '确定',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: '取消',
                        className: 'btn-danger'
                    }
                },
                callback: function (result) {
                    console.log('This was logged in the callback: ' + result);
                    if (result) {
                        $state.go('registered', {}, {reload: true});
                    } else {

                    }
                }
            });
        };
        vm.go_apply_activity = function () {
            // 获取用户信息
            if ($rootScope.id) {
                $http({
                    method: 'post',
                    url: sessionStorage.http + 'get_userinfo',
                    data: {
                        user_id: $rootScope.id
                    }
                })
                    .then(function successCallback(res) {
                        console.log(res.data);
                        if (res.data.code == 0) {
                            if (res.data.data.user.is_com == 0) {
                                // window.location.href = $rootScope.http_main + '/#/registered';
                                vm.choose();
                                console.log('is_com');
                                // $rootScope.alert('is_com');
                            } else {
                                vm.data1={};
                                console.log('1234567890');
                                vm.data1.activity_id = $stateParams.id;
                                vm.data1.user_id = $rootScope.id;
                                $http({
                                    method: 'post',
                                    url: vm.http + 'submit_activity',
                                    data: vm.data1
                                })
                                    .then(function successCallback(res) {

                                        if (res.data.code == 0) {
                                            vm.alert = !vm.alert;
                                            console.log(vm.alert);
                                        }
                                        else {
                                            $rootScope.alert(res.data.msg)
                                        }

                                    }, function errorCallback(res) {// 请求失败执行代码
                                        $rootScope.alertError()
                                    });
                            }
                        }
                    }, function errorCallback(res) {// 请求失败执行代码
                        // $rootScope.alertError()
                    });
            }
        }
    });